﻿using System.IO.Compression;

namespace CSharpPro._0929;

public class Demo
{

   /* public void TestPrint()
    {

        for (int i = 0; i < 10; i++)
        {
            if (i % 2 == 0)
            {
                Console.WriteLine(i);
            }
        }
    }

    public void TestPrint2()
    {
        try
        {
            int a = 10;
            int b = 0;
            int result = a / b;
            Console.WriteLine(result);
        }
        catch (Exception e)
        {
            Console.WriteLine(e);
            throw;
        }
    }

    public void TestPrint3()
    {
        for (int i = 100; i < 1000; i++)
        {
            int hundreds = i / 100;
            int tens = (i % 100) / 10;
            int units = i % 10;
            if (hundreds * hundreds * hundreds + tens * tens * tens + units * units * units == i)
            {
                Console.WriteLine(i);
            }

        }
    }

    public void TestPrint4()
    {
        for (int i = 2; i <= 100; i++)
        {
            bool prime = true;
            for (int j = 2; j <= Math.Sqrt(i); j++)
            {
                if (i % j == 0)
                {
                    prime = false;
                    break;
                }
            }

            if (prime)
            {
                Console.Write(i + " ");
            }
        }
    }*/

   
    public void TestPrint1()
    {
        Console.WriteLine("请输入第一个整数");
        int x = Convert.ToInt32(Console.ReadLine());
        Console.WriteLine("请输入第二个整数");
        int y = Convert.ToInt32(Console.ReadLine());
        Console.WriteLine("请输入第三个整数");
        int z = Convert.ToInt32(Console.ReadLine());
        int[] sum = { x, y, z };
        Array.Sort(sum);
        Console.WriteLine("从小到大排序后的结果为：{0}, {1}, {2}", sum[0], sum[1], sum[2]);
    }

    public void TestPrint2()
    {
        int sum = 0;
        for (int i = 1; i <= 100; i++)
        {
            if (i % 7 != 0 && !i.ToString().Contains("7"))
            {
                Console.Write(i + "");
                sum += i;
            }
        }

        Console.WriteLine("1到100之间所有不是7的倍数和不包含7的数字的和为" + sum);
    }

    public void TestPrint3()
    {
        for (int i = 1; i <= 9; i++)
        {
            for (int j = 1; j <= 9; j++)
            {
                Console.Write($"{j}×{i}={i * j}\t");
            }

            Console.WriteLine();
        }
    }

    public void TestPrint4()
    {
        for (int i = 2; i <= 1000; i++)
        {
            int sum = 0;
            for (int j = 1; j < i; j++)
            {
                if (i % j == 0)
                {
                    sum += j;
                }
            }

            if (sum == i)
            {
                Console.WriteLine(i + "");
            }
        }
    }

    public void TestPrint5()
    {
        Console.WriteLine("请输入一个正整数:");
        string input = Console.ReadLine();
        if (int.TryParse(input, out int num) && num > 0) //将字符串转为整数
        {
            int digitCount = input.Length; //判断几位数
            Console.WriteLine($"{num} 是 {digitCount} 位数");
            Console.Write("逆序各位数字");
            for (int i = input.Length - 1; i >= 0; i--)
            {
                Console.Write(input[i]);
            }

            Console.WriteLine();
        }
        else
        {
            Console.WriteLine("非法输入");
        }
    }

    public void TestPrint6()
    {
        Console.WriteLine("请输入菱形的行数（需为奇数）：");
        int rows = Convert.ToInt32(Console.ReadLine());
     
        if (rows % 2 == 0)
        {
            Console.WriteLine("请输入奇数行数！");
            return;
        }
        int mid = rows / 2;
  
        for (int i = 0; i <= mid; i++)
        {
        
            for (int j = 0; j < mid - i; j++)
            {
                Console.Write(" ");
            }
        
            for (int k = 0; k < 2 * i + 1; k++)
            {
                Console.Write("*");
            }
            Console.WriteLine();
        }
       
        for (int i = mid - 1; i >= 0; i--)
        {
       
            for (int j = 0; j < mid - i; j++)
            {
                Console.Write(" ");
            }
     
            for (int k = 0; k < 2 * i + 1; k++)
            {
                Console.Write("*");
            }
            Console.WriteLine();
        }
    }
    }